package com.ruoyi.web.pojo.request.devicedata;

import cn.hutool.core.net.url.UrlBuilder;
import com.ruoyi.common.utils.CommonUtils;
import com.ruoyi.web.enums.FactorEnum;
import com.ruoyi.web.utils.BasePageQuery;
import com.ruoyi.web.utils.influxdb.DeviceAggreDataParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;

/**
 * @desc  降雨量统计
 * @author fwx 2024/5/29 15:22
 **/
@Data
public class DeviceRainCountRequest extends BasePageQuery {

    @ApiModelProperty(value = "设备ID")
    @NotEmpty(message = "设备id不能为空")
    private String deviceId;

    @ApiModelProperty(value = "数据开始时间,格式 yyyy-MM-dd")
    private String startTime;

    @ApiModelProperty(value = "数据结束时间")
    private String endTime;

    @ApiModelProperty(value = "降雨的因子物模型名称")
    private String factor;

    @ApiModelProperty(value = "日期类型，1 全部，2 小时 , 3 日 , 4 月")
    private Integer dateType = 1;

    public void setEndTime(String endTime) {
        if(endTime != null){
            this.endTime = CommonUtils.computeTime(endTime,1);
        }
    }

    public DeviceAggreDataParam getDeviceAggreDataParam(Long productId){
        DeviceAggreDataParam param = new DeviceAggreDataParam();
        param.setDeviceId(deviceId);
        param.setStartTime(startTime);
        param.setEndTime(endTime);
        param.setFactor(factor);
        param.setFactorKey(FactorEnum.WH_RAIN.getKey());
        param.setProductId(productId);
        return param;
    }

    public UrlBuilder getQuery(){
        UrlBuilder builder = UrlBuilder.of();
        if (this.getDeviceId() != null)builder.addQuery("deviceId",this.getDeviceId());
        if (this.getStartTime() != null) builder.addQuery("startTime",this.getStartTime());
        if (this.getEndTime() != null) builder.addQuery("endTime",this.getEndTime());
        if (this.getFactor() != null) builder.addQuery("factor",this.getFactor());
        builder.addQuery("dateType",this.getDateType());

        return builder;
    }
}
